home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Programming
/
Programming Utilities
/
About… 2.1
/
About… 2.1 Demo Main.p
< prev
next >
Wrap
Text File
|
1992-01-01
|
32KB
|
938 lines
program AboutDemo; { Last Update : 1/1/92 }
{}
{ This program demonstrates the About… 2.1 Unit. }
{}
{ About… is copyrighted, and I reserve all rights to it; both source and }
{ compiled versions. Please do not distribute modified copies without my }
{ permission, or remove this notice. Thanks. }
{}
{ About is being distributed as $10 shareware. Reigstered users receive a}
{ diskette containing the Think Pascal source for the current version of}
{ About… and may use it and future versions in any program or programs}
{ you write. You need not credit me for its use.}
{}
{ Jon Wind (About…)}
{ 2374 Hillwood Drive}
{ Maplewood, MN 55119}
{}
{ Modal procedure: }
{ this routine does everything, returning to calling proc only after the window is dismissed... }
{• procedure BuildAbout (WinRect: Rect;}
{ WinProc, TEXTid: Integer;}
{ WinTitle, WinMsg: Str255;}
{ WinMisc: AboutRec);}
{ Modeless procedures: }
{ returns true if the specified window is an About window; otherwise returns false }
{• function IsAboutWindow (theWindow: WindowPtr): Boolean;}
{ open About window and return pointer to it - returns NIL if window is not created }
{ Note: you should keep track of this pointer only if you wish to keep specific track of it }
{• function OpenAbout (WinRect: Rect;}
{ WinProc, TEXTid: Integer;}
{ WinTitle, WinMsg: Str255;}
{ WinMisc: AboutRec): WindowPtr;}
{ handle event relating to About window, ie updateEvt, activateEvt, mouseDown, keyDown, etc… }
{ Note: this proc should be called after every event for each About window for everything to work correctly }
{ Note: this proc calls the CloseAbout proc if the OK button is selected }
{ Note: you can filter events passed to it to simulate a modal dialog }
{• procedure HandleAbout (var theWindow: WindowPtr;}
{ var theEvent: EventRecord);}
{ close the specified About window, kill data structures associated with it, and set theWindow to NIL… }
{ Note: this proc is called by the HandleAbout proc when an About window is dismissed by selecting its OK button }
{ Note: this proc should be called when the program needs to remove an About window }
{• procedure CloseAbout (var theWindow: WindowPtr);}
uses
About, { …my unit! }
Globals, { program globals }
DemoUtils; { general utils }
procedure DoHelp;
{ Display modal help dialog - not a lot of code needed... }
var
HelpWinRect: Rect;
SavePort: GrafPtr;
begin
GetPort(SavePort); { save current port }
SetPort(MainDlgPtr);
EraseRect(ramRect); { memory count won't be accurate during modal display, so lose it }
InvalRect(ramRect);
with AboutStuff do { set up the text stuff to be used by the About... unit }
begin
FontInfo[AboutMsg].Font := Geneva; { use Geneva for Message }
FontInfo[AboutMsg].Size := 9; { use 9 point for Message }
FontInfo[AboutMsg].Face := [outline]; { use outline face for Message }
FontInfo[AboutMsg].Color := GreenColor; { use green for Message }
FontInfo[AboutTEXT].Font := Monaco; { use Monaco for TEXT - 'styl' resource may override }
FontInfo[AboutTEXT].Size := 9; { use 9 point for TEXT - 'styl' resource may override }
FontInfo[AboutTEXT].Face := [bold]; { use bold face for TEXT - 'styl' resource may override }
FontInfo[AboutTEXT].Color := RedColor; { use red for TEXT - 'styl' resource may override }
TEXTCopy := True; { allow copy to clipboard }
KeyEquivs := True; { allow key equivalents }
CloseBox := False; { set close box Boolean }
Styled := True; { set use of styled text (if possible) }
CenterMode := AboutMainCenter; { center window }
MainIcon := 1000; { use icon }
ClickIcon := AboutNoIcon; { no new icon when original is clicked on - use MainIcon if only new message is desired }
ClickMsg := ''; { no click message - no need to define if ClickIcon = AboutNoIcon }
end;
SetRect(HelpWinRect, 0, 0, 420, 257);
BuildAbout(HelpWinRect, dBoxProc, HelpTEXTID, '', CopyrightMsg, AboutStuff);
SetPort(SavePort); { save current port }
end;
procedure PutRectVarInDialog;
{ put current values into edit text boxes and set buttons }
begin
ChangeChoiceText(MainDlgPtr, dTopEd, aNum2Str(zVar.WinRect.top));
ChangeChoiceText(MainDlgPtr, dLeftEd, aNum2Str(zVar.WinRect.left));
ChangeChoiceText(MainDlgPtr, dRightEd, aNum2Str(zVar.WinRect.right));
ChangeChoiceText(MainDlgPtr, dBottomEd, aNum2Str(zVar.WinRect.bottom));
end; { of proc PutRectVarInDialog }
procedure FixCloseCheckbox;
begin
if (WinTypePop.Selected = dNoGrowWin) or (WinTypePop.Selected = dRDocWWin) then
SetCheckOrRadioBtn(MainDlgPtr, dCloseChk, Ord(zVar.Close)) { restore checkbox to actual value }
else
begin
SetCheckOrRadioBtn(MainDlgPtr, dCloseChk, Off); { uncheck checkbox - no need to change zClose var though... }
SetCheckOrRadioBtn(MainDlgPtr, dCloseChk, Disable); { disable checkbox }
end;
end;{of proc FixCloseCheckbox }
procedure PutVarsInDialog;
{ put current values into edit text boxes and set buttons }
begin
SetCheckOrRadioBtn(MainDlgPtr, dMsgChk, Ord(zVar.Msg)); { set use message text checkbox }
SetCheckOrRadioBtn(MainDlgPtr, Succ(dCenterRad) + zVar.Center, On); { set Center Window radio }
SetCheckOrRadioBtn(MainDlgPtr, dIconChk, Ord(zVar.ShowIcon)); { set Show Icon checkbox }
SetCheckOrRadioBtn(MainDlgPtr, dStylChk, Ord(zVar.Style)); { set use styled text checkbox }
SetCheckOrRadioBtn(MainDlgPtr, dCopyChk, Ord(zVar.CopyIt)); { set copy to clipboard checkbox }
SetCheckOrRadioBtn(MainDlgPtr, dCloseChk, Ord(zVar.Close)); { set close box checkbox }
SetCheckOrRadioBtn(MainDlgPtr, dEquivChk, Ord(zVar.Keys)); { set key equivalents checkbox }
PutRectVarInDialog;
ChangeChoiceText(MainDlgPtr, dTitleEd, zVar.TitleText);
ChangeChoiceText(MainDlgPtr, dMsgEd, zVar.MsgText);
SelItext(MainDlgPtr, dTopEd, 0, maxint);
end; { of proc PutVarsInDialog }
procedure DrawFreeRam;
{ display current free memory }
var
origFont, origSize: Integer;
SavePort: GrafPtr;
fontStuff: FontInfo;
ramStr: Str255;
begin
GetPort(SavePort); { save current port }
SetPort(MainDlgPtr);
origFont := MainDlgPtr^.txFont;
origSize := MainDlgPtr^.txSize;
ramFree := FreeMem;
NumToString(ramFree, ramStr);
EraseRect(ramRect);
TextSize(9);
TextFont(Geneva);
GetFontInfo(fontStuff);
MoveTo(ramrect.left, ramRect.bottom - fontStuff.descent);
DrawString(Concat(ramStr, ' bytes free'));
TextFont(origFont);
TextSize(origSize);
SetPort(SavePort); { restore old port }
end; { of proc DrawFreeRam }
function GetNextWinHdl: Integer;
var
j: SignedByte;
begin
GetNextWinHdl := 0;
for j := 1 to maxDemoWindows do
if DemoWinPtr[j] = nil then
begin
GetNextWinHdl := j;
leave;
end;
end; { of func GetNextWinHdl }
procedure DemoAbout;
var
aWin: SignedByte;
begin
case WinTypePop.Selected of
dBoxWWin:
zVar.WinProc := dBoxProc;
dPlainWWin:
zVar.WinProc := plainDBox;
dAltWWin:
zVar.WinProc := altDBoxProc;
dNoGrowWin:
zVar.WinProc := noGrowDocProc;
dRDocWWin:
zVar.WinProc := rDocProc;
dMovableWin:
zVar.WinProc := movableDBoxProc;
end;
with AboutStuff do { set up the text stuff to be used by the About... unit }
begin
FontInfo[AboutMsg].Font := 0; { use Chicago for Message }
FontInfo[AboutMsg].Size := 0; { use 12 point for Message }
FontInfo[AboutMsg].Face := []; { use normal face for Message }
FontInfo[AboutMsg].Color := BlueColor; { use blue for Message }
FontInfo[AboutTEXT].Font := Geneva; { use Geneva for TEXT - 'styl' resource may override }
FontInfo[AboutTEXT].Size := 9; { use 9 point for TEXT - 'styl' resource may override }
FontInfo[AboutTEXT].Face := []; { use normal face for TEXT - 'styl' resource may override }
FontInfo[AboutTEXT].Color := GreenColor; { use green for TEXT - 'styl' resource may override }
TEXTCopy := zVar.CopyIt; { set copy to clipboard Boolean }
KeyEquivs := zVar.Keys; { set key equivalents Boolean }
if (zVar.WinProc = plainDBox) and (not zVar.ShowIcon) and ((Length(zVar.MsgText) = 0) or not zVar.Msg) then
CloseBox := False { force no close box for this condition in this demo }
else
CloseBox := zVar.Close; { set close box Boolean }
Styled := zVar.Style; { set use of styled text (if possible) }
CenterMode := zVar.Center; { set center window integer }
if zVar.ShowIcon then
MainIcon := IconID
else { Note: use contant "AboutNoIcon" to indicate no icon }
MainIcon := AboutNoIcon;
ClickIcon := IconID + 1;
ClickMsg := SharewareMsg;
end;
zVar.WinRect.top := aStr2Num(GetEdText(MainDlgPtr, dTopEd));
zVar.WinRect.left := aStr2Num(GetEdText(MainDlgPtr, dLeftEd));
zVar.WinRect.right := aStr2Num(GetEdText(MainDlgPtr, dRightEd));
zVar.WinRect.bottom := aStr2Num(GetEdText(MainDlgPtr, dBottomEd));
zVar.TitleText := GetEdText(MainDlgPtr, dTitleEd);
zVar.MsgText := GetEdText(MainDlgPtr, dMsgEd);
PutRectVarInDialog; { stuff rect values back into text fields }
SelItext(MainDlgPtr, Succ(DialogPeek(MainDlgPtr)^.editField), 0, 0); { deselect text }
{ find first available window pointer in array }
aWin := GetNextWinHdl;
if aWin > 0 then
begin
if zVar.Msg then
begin
if zVar.Modal then
begin
BuildAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, zVar.MsgText, AboutStuff);
Exit(DemoAbout);
end
else
DemoWinPtr[aWin] := OpenAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, zVar.MsgText, AboutStuff)
end
else
begin
if zVar.Modal then
begin
BuildAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, '', AboutStuff);
Exit(DemoAbout);
end
else
DemoWinPtr[aWin] := OpenAbout(zVar.WinRect, zVar.WinProc, AboutTEXTID, zVar.TitleText, '', AboutStuff);
end;
if DemoWinPtr[aWin] <> nil then { window was built }
begin
DrawFreeRam; { update free memory display }
{ Disable OK button if there are no more window handles free }
if GetNextWinHdl = 0 then
begin
SetCheckOrRadioBtn(MainDlgPtr, OK, Disable); { disable OK button since all handles are in use }
DrawDefaultBtn(MainDlgPtr, OK);
end;
end
else
SysBeep(3); { window was not built }
end;
end; { of proc DemoAbout }
procedure DealwithKeyDowns (var Event: EventRecord);
var
j: SignedByte;
theWindow, origWindow: WindowPtr;
theKey, FieldInUse, whichItem: Integer;
TEPeek: DialogPeek;
CmdKeyUsd: Boolean;
err: OSErr;
begin
theWindow := FrontWindow;
if IsAboutWindow(theWindow) then
begin
origWindow := theWindow; { save original window pointer }
HandleAbout(theWindow, Event);
if theWindow = nil then { About window was killed }
for j := 1 to maxDemoWindows do { remove entry window pointer array }
if DemoWinPtr[j] = origWindow then
begin
DemoWinPtr[j] := nil;
SetCheckOrRadioBtn(MainDlgPtr, OK, Off); { enable OK button since at least one handle is not in use }
DrawDefaultBtn(MainDlgPtr, OK);
end;
end
else if (GetWRefCon(theWindow) = AboutDemoID) then
begin
whichItem := 0;
TEPeek := DialogPeek(theWindow);
FieldInUse := TEPeek^.editField + 1; { get # of edit field in use }
theKey := BitAnd(Event.message, charCodeMask); { decode char }
CmdKeyUsd := (BitAnd(Event.modifiers, cmdKey) <> 0); { cmd key down? }
if (FieldInUse <> dMsgEd) and (theKey = CR) then { allow CRs in msg text field }
theKey := enterKey;
case theKey of
enterKey: { OK Button equivalents }
begin
whichItem := -1; { hides key }
if CtrlEnabled(theWindow, OK) then
begin
FakeClick(theWindow, OK);
DemoAbout;
end;
end;
lowerC, upperC: { not needed with System 7.0! }
if CmdKeyUsd then
begin { copy selection to clipboard }
DlgCopy(theWindow);
if TEGetScrapLen > 0 then
if ZeroScrap = noErr then
Err := TEtoScrap;
whichItem := -1; { hides key }
end
else if FieldInUse <= dBottomEd then
whichItem := -1; { hides non-numeric keys }
lowerV, upperV: { not needed with System 7.0! }
if CmdKeyUsd then
begin { paste clipboard }
Err := TEfromScrap;
if TEGetScrapLen > 0 then
DlgPaste(theWindow);
whichItem := -1; { hides key }
end
else if FieldInUse <= dBottomEd then
whichItem := -1; { hides non-numeric keys }
lowerX, upperX: { not needed with System 7.0! }
if CmdKeyUsd then
begin { cut selection to clipboard }
DlgCut(theWindow);
if TEGetScrapLen > 0 then
if ZeroScrap = noErr then
Err := TEtoScrap;
whichItem := -1; { hides key }
end
else if FieldInUse <= dBottomEd then
whichItem := -1; { hides non-numeric keys }
downArrow:
if TabSelectText(theWindow, goNext) then
whichItem := -1; { hides key }
upArrow:
if TabSelectText(theWindow, goPrev) then
whichItem := -1; { hides key }
tabKey:
if BitAnd(Event.modifiers, shiftKey) <> 0 then { shift key down }
if TabSelectText(theWindow, goPrev) then
whichItem := -1; { hides key }
otherwise
if FieldInUse <= dBottomEd then
if not (theKey in [num0..num9, BS, leftArrow, rightArrow]) then
whichItem := -1; { hides non-numeric keys }
end;
if whichItem < 0 then
Event.what := 0; { 'EAT' processed cmd key }
end;
end; { of proc DealwithKeyDowns }
function GetGrayRgn: RgnHandle;
{ get gray region }
var
thePtr: ^RgnHandle;
begin
thePtr := Pointer($9EE);
GetGrayRgn := thePtr^;
end; { of func GetGrayRgn }
procedure rotateByte (p: Ptr);
inline
$205F, $1010, $E218, $1080;
{ move.l (sp)+,a0}
{ move.b (a0),d0}
{ ror.b #1,d0}
{ move.b d0,(a0)}
procedure HandleSetRect (theDialog: DialogPtr);
{ deal with set rect for sample window }
var
j, itmType, winKind, totItems, height, width: Integer;
startPt, endPt: Point;
oldRect, titleRect, theRect: Rect;
deskPort: GrafPtr;
mouseEvent: EventRecord;
itmHdl: Handle;
rgnHdl: RgnHandle;
IntPtr: ^Integer;
marqueePat: Pattern;
lastDraw: LongInt;
theString: Str255;
done: Boolean;
Wind: WindowPtr;
procedure DrawMarquee (oldRect, newRect: Rect);
var
i: Integer;
begin
lastDraw := TickCount;
for i := 0 to 7 do { set up blinking marquee pattern by shifting bits }
rotateByte(@marqueePat[i]);
FrameRect(oldRect); { erase old rect }
PenPat(marqueePat);
FrameRect(newRect); { draw new rect }
end; { of proc DrawMarquee }
begin
SelItext(theDialog, Succ(DialogPeek(theDialog)^.editField), 0, 0); { deselect text }
IntPtr := Pointer(DialogPeek(theDialog)^.Items^);
totItems := Succ(IntPtr^); { total # of items in dialog }
PenPat(gray);
PenMode(patBic); { to gray existing text... }
PaintRect(theDialog^.portRect); { "gray out" text }
PenNormal;
SetBtnTitle(theDialog, dSetRectBtn, dSetRectBtnStr2); { change btn title to help user & force btn redraw }
for j := 1 to 4 do { redraw rect coordinates so they're not gray }
begin
GetDItem(theDialog, (Pred(j) * 2) + dTopEd, itmType, itmHdl, oldRect); { get button location }
GetIText(itmHdl, theString);
SetIText(itmHdl, theString);
end;
GetWTitle(theDialog, theString);
SetWTitle(theDialog, 'Click and Drag or Press a Key to Cancel');
{ setup rect to use to gray title bar - bad idea since it may not work with alternate WDEFs...}
titleRect := theDialog^.portRect;
LocalToGlobal(titleRect.topLeft);
LocalToGlobal(titleRect.botRight);
OffsetRect(titleRect, 0, -18);
titleRect.bottom := titleRect.top + 16;
GetDItem(theDialog, dSetRectBtn, itmType, itmHdl, oldRect); { get button location }
LocalToGlobal(oldRect.topLeft);
LocalToGlobal(oldRect.botRight);
New(deskPort);
OpenPort(deskPort); { make grafport so can draw on screen }
UnionRgn(GetGrayRgn, deskPort^.visRgn, deskPort^.visRgn); { add all monitors to visRgn of new grafPort }
{ here I remove the "Set" button from the clip region since I'll be changing its title and this }
{ eliminates the possibility of gray line artifacts left from using the notPatXOr drawing mode }
{ ...trust me... }
rgnHdl := NewRgn;
OpenRgn;
FrameRoundRect(oldRect, 16, 16); { create button size region to remove from new grafPort }
CloseRgn(rgnHdl);
DiffRgn(deskPort^.clipRgn, rgnHdl, deskPort^.clipRgn); { remove button from clip region }
DisposeRgn(rgnHdl);
StuffHex(@marqueePat, '0F1E3C78F0E1C387');
lastDraw := 0;
oldRect := zVar.WinRect;
PenMode(notPatXor); { allows easy redrawing of gray frames }
SetCursor(CrossCurs^^); { bring up cross cursor }
{ create a dBoxProc dialog beyond the edge of the screen under the menu bar to stop MF switching }
SetRect(theRect, 0, 0, 5, 5);
wind := NewWindow(nil, theRect, '', True, dBoxProc, Pointer(-1), False, 0);
repeat
if (TickCount > lastDraw + 1) then
DrawMarquee(oldRect, oldRect);
done := GetNextEvent(mDownMask + keyDownMask, mouseEvent);
until done; { wait for mousedown }
FrameRect(oldRect); { erase old rect }
PenPat(gray);
{ kill hidden dialog }
DisposeWindow(wind);
if mouseEvent.what = mouseDown then { key stroke allows rect to be unchanged }
begin
PenMode(patBic);
PaintRect(titleRect); { gray title bar - bad idea since it may not work with alternate WDEFs...}
PenMode(notPatXor); { allows easy redrawing of gray frames }
SetRect(oldRect, 0, 0, 0, 0);
zVar.WinRect := oldRect;
startPt := mouseEvent.where; { globals are OK }
repeat { repeat until mouse button is released }
GetMouse(endPt);
if (endPt.h > startPt.h) and (endPt.v > startPt.v) then
SetRect(zVar.WinRect, startPt.h, startPt.v, endPt.h, endPt.v)
else if (endPt.h > startPt.h) and (endPt.v < startPt.v) then
SetRect(zVar.WinRect, startPt.h, endPt.v, endPt.h, startPt.v)
else if (endPt.h < startPt.h) and (endPt.v > startPt.v) then
SetRect(zVar.WinRect, endPt.h, startPt.v, startPt.h, endPt.v)
else
SetRect(zVar.WinRect, endPt.h, endPt.v, startPt.h, startPt.v);
if ShiftDown then { constrain rect to size of shortest side }
with zVar.WinRect do
begin
height := bottom - top;
width := right - left;
if width > height then
if startPt.h = left then { height < width }
right := left + height
else
left := right - height
else if startPt.v = top then { width < height }
bottom := top + width
else
top := bottom - width
end;
if (zVar.WinRect.right - zVar.WinRect.left >= 150) and (zVar.WinRect.bottom - zVar.WinRect.top >= 100) then
SetBtnTitle(theDialog, dSetRectBtn, dSetRectBtnStr3) { change btn title to help user }
else
SetBtnTitle(theDialog, dSetRectBtn, dSetRectBtnStr4); { change btn title to help user }
if not EqualRect(oldRect, zVar.WinRect) then { update for new rect }
begin
PutRectVarInDialog; { update window rect display }
DrawMarquee(oldRect, zVar.WinRect);
oldRect := zVar.WinRect; { save current rect for later erasure }
end;
if (TickCount > lastDraw + 1) then
DrawMarquee(oldRect, oldRect);
until not stilldown;
FrameRect(oldRect); { erase last rect }
end;{ of mouseEvent.what = mouseDown }
PenNormal;
InitCursor; { restore arrow cursor }
SetBtnTitle(theDialog, dSetRectBtn, dSetRectBtnStr); { restore btn title }
ClosePort(deskPort); { done with port - get rid of it }
Dispose(deskPort);
SetPort(theDialog); { be sure main window is current window }
SetWTitle(theDialog, theString);
InvalRect(theDialog^.portRect);
end; { of proc HandleSetRect }
procedure DealwithDialogs (Event: EventRecord);
var
dlgPtr: DialogPtr;
itemHit, j, itmType, winKind, totItems: Integer;
err: OSErr;
ItemWasHit, fix: Boolean;
begin
case Event.what of
keydown, autokey:
begin
DealwithKeyDowns(Event);
if ((Event.what = keydown) | (Event.what = autokey)) & (DialogSelect(Event, dlgPtr, ItemHit)) then
; { if Event was not altered by DealwithKeyDowns, pass key along to dialog manager }
end;
ActivateEvt:
if GetWRefCon(WindowPtr(Event.message)) = AboutDemoID then
DrawDefaultBtn(WindowPtr(Event.message), OK);
UpdateEvt:
if GetWRefCon(WindowPtr(Event.message)) = AboutDemoID then
begin
BeginUpdate(MainDlgPtr); { this method preserves the window's custom background color - if any }
FixWindowColor(MainDlgPtr);
DrawDialog(MainDlgPtr);
EndUpdate(MainDlgPtr);
UpdatePopUp(WindowPtr(Event.message), WinTypePop);
DrawFreeRam; { update free memory display }
end;
otherwise
if DialogSelect(Event, dlgPtr, ItemHit) & (GetWRefCon(dlgPtr) = AboutDemoID) then
begin
SetPort(dlgPtr);
case itemHit of
OK:
DemoAbout;
Cancel:
Finished := True;
dSetRectBtn: { Set window rect }
HandleSetRect(dlgPtr);
dWinProcPop:
if HandlePopUpSelect(dlgPtr, WinTypePop) then
begin
UpdatePopUp(MainDlgPtr, WinTypePop);
FixCloseCheckbox;
end;
dMsgChk:
begin
zVar.Msg := not zVar.Msg;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.Msg));
end;
dCenterRad..dMainMonRad:
begin
ItemWasHit := ((itemHit - Succ(dCenterRad) = zVar.Center) & (TickCount - lastClick < GetDblTime));
SetCheckOrRadioBtn(MainDlgPtr, Succ(dCenterRad) + zVar.Center, Off); { set Center Window radio }
zVar.Center := itemHit - Succ(dCenterRad);
SetCheckOrRadioBtn(MainDlgPtr, Succ(dCenterRad) + zVar.Center, On); { set Center Window radio }
if ItemWasHit then
err := PostEvent(keyDown, enterKey);
lastClick := TickCount;
end;
dIconChk:
begin
zVar.ShowIcon := not zVar.ShowIcon;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.ShowIcon));
end;
dStylChk:
begin
zVar.Style := not zVar.Style;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.Style));
end;
dCopyChk:
begin
zVar.CopyIt := not zVar.CopyIt;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.CopyIt));
end;
dCloseChk:
begin
zVar.Close := not zVar.Close;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.Close));
end;
dEquivChk:
begin
zVar.Keys := not zVar.Keys;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.Keys));
end;
dModalChk:
begin
zVar.Modal := not zVar.Modal;
SetCheckOrRadioBtn(dlgPtr, itemHit, Ord(zVar.Modal));
end;
dAboutBtn: { ? button }
DoHelp;
otherwise
end;
end;
end;
end; { of proc DealwithDialogs }
procedure DealwithMouseDowns (Event: EventRecord);
var
j: SignedByte;
WindowPointedTo, theWindow: WindowPtr;
MouseLoc: Point;
WindoLoc: integer;
begin
MouseLoc := Event.Where;
WindoLoc := FindWindow(MouseLoc, WindowPointedTo);
if IsAboutWindow(WindowPointedTo) then
begin
theWindow := WindowPointedTo; { save original window pointer }
HandleAbout(WindowPointedTo, Event);
if WindowPointedTo = nil then { About window was killed }
for j := 1 to maxDemoWindows do { remove entry from window pointer array }
if DemoWinPtr[j] = theWindow then
begin
DemoWinPtr[j] := nil;
SetCheckOrRadioBtn(MainDlgPtr, OK, Off); { enable button }
DrawDefaultBtn(MainDlgPtr, OK);
end;
end
else
begin
case WindoLoc of
inMenuBar:
;
inSysWindow:
;
inContent:
if WindowPointedTo <> FrontWindow then
begin
SelectWindow(WindowPointedTo); { bring to front }
while WindowPointedTo <> nil do
begin
HandleAbout(WindowPointedTo, Event); { pass event to About Unit }
WindowPointedTo := WindowPtr(WindowPeek(WindowPointedTo)^.nextWindow);
end;
end
else
begin {do something}
sysbeep(1);
end;
inGrow:
;
InDrag: { click in drag bar }
begin
DragWindow(WindowPointedTo, MouseLoc, ScreenBits.bounds);
end;
inGoAway:
if TrackGoAway(WindowPointedTo, MouseLoc) then
DisposeWindow(WindowPointedTo); {since W mgr allocated space}
otherwise
end;{ of case}
end;
end; { of proc DealwithMouseDowns }
procedure DealwithActivates (Event: EventRecord);
var
TargetWindow: WindowPtr;
begin
TargetWindow := WindowPtr(Event.message);
if IsAboutWindow(TargetWindow) then
HandleAbout(TargetWindow, Event)
else
begin
if Odd(Event.modifiers) then {then the window is becoming active}
begin
SetPort(TargetWindow);
{and activate whatever else you need}
{the scroll bars}
{hilite selected text}
end
else
begin
{deactivate whatever you need}
{deactivate the scroll bars}
{UNhilite selected text}
end;
end;
end; { of proc DealwithActivates }
procedure DealwithUpdates (Event: EventRecord);
var
UpDateWindow: WindowPtr;
begin
UpdateWindow := WindowPtr(Event.message);
if IsAboutWindow(UpdateWindow) then
HandleAbout(UpdateWindow, Event)
else
begin
SetPort(UpdateWindow); {set the port to one in Evt.msg}
BeginUpDate(UpdateWindow);
DrawDialog(UpdateWindow);
EndUpDate(UpdateWindow);
end;
end; { of proc DealwithUpdates }
procedure MainEventLoop;
var
Event: EventRecord;
ProcessIt: Boolean;
NextWinPeek, WinPeek: WindowPeek;
begin
repeat
PurgeMem(ramDemand);
if (ramFree <> FreeMem) then
DrawFreeRam; { update free memory display }
SystemTask; {so you can support Desk Accessories}
ProcessIt := GetNextEvent(EveryEvent, Event);
if IsDialogEvent(Event) then
DealwithDialogs(Event)
else if ProcessIt then{is true}
case Event.what of
mouseDown:
DealwithMouseDowns(Event);
keydown, autokey:
DealwithKeyDowns(Event);
ActivateEvt:
DealwithActivates(Event);
UpDateEvt:
DealwithUpdates(Event);
otherwise
end;{of Case}
until Finished; {terminate the program}
{ destroy any open About windows… }
WinPeek := WindowPeek(FrontWindow);
while WinPeek <> nil do
begin
NextWinPeek := WinPeek^.nextWindow; { if it's window is an About window, it's history - save next window pointer }
if IsAboutWindow(WindowPtr(WinPeek)) then { is it an About window? }
begin
CloseAbout(WindowPtr(WinPeek)); { then kill it…}
DrawFreeRam; { update free memory display }
end;
WinPeek := NextWinPeek;
end;
{ finally, destroy main dialog }
DisposDialog(MainDlgPtr);
{ release menu too… - not strictly necessary for this demo }
ReleaseResource(Handle(WinTypePop.MenuHndl));
end; { of proc MainEventLoop }
function OpenColorDlg (dlgID: Integer): DialogPtr;
{ open regular B&W or color dialog - allows for accurate display of custom content color }
var
hasColor: Boolean;
theWorld: SysEnvRec;
dlgPtr: DialogPtr;
aRect: Rect;
DITLhndl: Handle;
WinTitle: Str255;
procID: Integer;
begin
if (SysEnvirons(1, theWorld) <> envNotPresent) then { SysEnvirons call is available }
hasColor := theWorld.hasColorQD { has Color QuickDraw }
else
hasColor := False;
if hasColor then
begin
dlgPtr := getNewDialog(dlgID, nil, Pointer(-1)); { get dialog box }
aRect := dlgPtr^.portRect;
GetWTitle(dlgPtr, WinTitle);
procID := GetWVariant(dlgPtr); { GetWVariant func requires MacPlus or better }
DisposDialog(dlgPtr);
DITLhndl := Get1Resource('DITL', dlgID);
dlgPtr := NewCDialog(nil, aRect, WinTitle, False, procID, WindowPtr(nil), False, 0, DITLhndl);
end
else
dlgPtr := getNewDialog(dlgID, nil, Pointer(-1)); { get B&W dialog box }
OpenColorDlg := dlgPtr;
end; { of func OpenColorDlg }
procedure Initialize;
var
j: SignedByte;
theRect: Rect;
aHdl: Handle;
height, theItem: Integer;
fontStuff: FontInfo;
begin
CrossCurs := GetCursor(crosscursor); { read in from system resource }
HLock(Handle(CrossCurs)); { lock the handle down }
for j := 1 to maxDemoWindows do
DemoWinPtr[j] := nil;
Finished := False;
zVar.Center := AboutNoCenter;
zVar.Msg := True;
zVar.ShowIcon := True;
zVar.Style := True;
zVar.CopyIt := True;
zVar.Close := True;
zVar.Keys := True;
zVar.Modal := False;
zVar.MsgText := Concat(AboutVersion, ' Unit', chr(CR), CopyrightMsg);
zVar.TitleText := Concat(AboutVersion, ' Demo');
SetRect(zVar.WinRect, 22, 42, 432, 291); { set default window rect }
lastClick := TickCount;
SetRect(ramRect, 1, 0, 120, 10);
ramDemand := maxint * 10;
ramFree := 0;
WinTypePop.MenuHndl := GetMenu(WinProcMenuID);
WinTypePop.Selected := dBoxWWin;
WinTypePop.PopDItem := dWinProcPop;
WinTypePop.canInvert := True;
MainDlgPtr := OpenColorDlg(AboutDemoID);
SetWRefCon(MainDlgPtr, AboutDemoID); { store ID for use in distinguishing window later… }
{ setup dialog item, popup menu, and popup menu record with correct values }
GetDItem(MainDlgPtr, Pred(WinTypePop.PopDItem), theItem, aHdl, WinTypePop.promptRect); { get item's rect }
GetDItem(MainDlgPtr, WinTypePop.PopDItem, theItem, aHdl, WinTypePop.PopUpRect); { get item's rect }
with WinTypePop do
begin
{ limit width of popup menu item - reduce as needed }
CalcMenuSize(MenuHndl);
if PopUpRect.right > PopUpRect.left + MenuHndl^^.menuWidth then
begin
GetDItem(MainDlgPtr, PopDItem, theItem, aHdl, PopUpRect); { get item's rect }
PopUpRect.right := PopUpRect.left + MenuHndl^^.menuWidth;
SetDItem(MainDlgPtr, PopDItem, theItem, aHdl, PopUpRect);
end;
{ adjust height of popup menu item - enlarge or reduce as needed }
GetFontInfo(fontStuff);
height := (fontStuff.ascent + fontStuff.descent + 2);
if (PopUpRect.bottom - PopUpRect.top < 18) | (PopUpRect.bottom - PopUpRect.top < height) then { 18 = min for SICNs }
begin
GetDItem(MainDlgPtr, PopDItem, theItem, aHdl, PopUpRect); { get item's rect }
SetRect(theRect, PopUpRect.left, PopUpRect.top, PopUpRect.right, PopUpRect.top + height);
VertCenterRect(theRect, PopUpRect);
PopUpRect := theRect;
SetDItem(MainDlgPtr, PopDItem, theItem, aHdl, PopUpRect);
end;
end;
InsertMenu(WinTypePop.MenuHndl, hierMenu); { insert as popup/hierarchical }
{ let Dialog Manager draw RoundRect around default btn }
SetRect(theRect, 0, 0, 0, 0);
SetDItem(MainDlgPtr, 3, userItem, @DrawDefaultBtn, theRect);
CenterWindow(MainDlgPtr); { center,display,set port,default btn }
PutVarsInDialog; { put window rect values into edit text boxes }
FixCloseCheckbox;
InitCursor;
end; { of proc Initialize }
{main program loop}
begin
Initialize;
MainEventLoop;
end.